package com.party.core.service.sign.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.UUIDUtils;
import com.party.core.dao.read.sign.MemberSignDetailReadDao;
import com.party.core.dao.write.sign.MemberSignDetailWriteDao;
import com.party.core.model.sign.MemberSignDetail;
import com.party.core.service.sign.IMemberSignDetailService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Author: huangzequn
 * @Date: 2019/4/16 11:06
 */
@Service
public class MemberSignDetailService implements IMemberSignDetailService {

    @Autowired
    MemberSignDetailReadDao memberSignDetailReadDao;

    @Autowired
    MemberSignDetailWriteDao memberSignDetailWriteDao;

    /**
    * @Author hzq
    * @Description //TODO
    * @Date 11:19 2019/4/16
    * @param memberSignDetail
    * @return
    **/
    @Override
    public String insert(MemberSignDetail memberSignDetail) {
        memberSignDetail.setId(UUIDUtils.generateRandomUUID());
        boolean result = memberSignDetailWriteDao.insert(memberSignDetail);
        if (result){
            return memberSignDetail.getId();
        }
        return null;
    }

    /**
    * @Author hzq
    * @Description //TODO
    * @Date 11:19 2019/4/16
    * @param memberSignDetail
    * @return
    **/
    @Override
    public boolean update(MemberSignDetail memberSignDetail) {
        return memberSignDetailWriteDao.update(memberSignDetail);
    }

    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return memberSignDetailWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return memberSignDetailWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return memberSignDetailWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return memberSignDetailWriteDao.batchDelete(ids);
    }

    @Override
    public MemberSignDetail get(String id) {
        return memberSignDetailReadDao.get(id);
    }

    @Override
    public List<MemberSignDetail> listPage(MemberSignDetail memberSignDetail, Page page) {
        return memberSignDetailReadDao.listPage(memberSignDetail, page);
    }

    @Override
    public List<MemberSignDetail> list(MemberSignDetail memberSignDetail) {
        return memberSignDetailReadDao.listPage(memberSignDetail, null);
    }

    @Override
    public List<MemberSignDetail> batchList(Set<String> ids, MemberSignDetail memberSignDetail, Page page) {
        return memberSignDetailReadDao.batchList(ids, new HashedMap(), page);
    }

    /**
     * @Author hzq
     * @Description //根据signId，yearMonth查询
     * @Date 17:03 2019/4/16
     * @param signId
     * @param yearMonth 年月 '2019-04'
     * @return
     **/
    @Override
    public List<MemberSignDetail> getByYearMonth(String signId, String yearMonth, Page page) {
        return memberSignDetailReadDao.getByYearMonth(signId,yearMonth,page);
    }

    /**
    * @Author hzq
    * @Description //TODO
    * @Date 15:14 2019/4/17
    * @param signId
    * @param day
    * @return
    **/
    @Override
    public MemberSignDetail getByDay(String signId, Date day) {
        return memberSignDetailReadDao.getByDay(signId,day);
    }
}
